﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

namespace DetectFileChange
{
    class FileSystemWatch
    {
        private const string DIR = ".";
        private static bool flag;
        static void Main(string[] args)
        {
            flag = false;
            FileSystemWatcher watcher = new FileSystemWatcher(DIR,"asd.txt");
            watcher.EnableRaisingEvents = true;
            watcher.NotifyFilter = NotifyFilters.LastWrite;
            watcher.Changed += new FileSystemEventHandler(watcher_Changed);
            string line = Console.ReadLine();
            using (ManualResetEvent resetEvent = new ManualResetEvent(false))
            {
                while (true)
                {
                    resetEvent.WaitOne();
                }
            }
            
        }

        static void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            flag = true;            
            Console.WriteLine();
            Console.WriteLine(File.ReadAllText(e.Name));
        }
    }
}
